package com.fx.device.controller.activit;


import com.fx.device.common.util.ReturnMessage;
import com.fx.device.service.activit.ProcessInstanceService;
import com.fx.device.vo.activit.ProUser;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/processInstance")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class ProcessInstanceController {


    final private ProcessInstanceService service;


    //查询流程实例
    @GetMapping(value = "/getInstances")
    //@AuthenticationPrincipal ProUser proUser，如需获取当前登录人信息，仅加入此参数即可
    public ReturnMessage<Object> getInstances(@AuthenticationPrincipal ProUser proUser, @RequestParam("page") int page,
                                              @RequestParam("size") int size) {

        return service.getInstances(proUser, page, size);


    }


    //启动
    @GetMapping(value = "/startProcess")
    public ReturnMessage<Object> startProcess(@RequestParam("processDefinitionKey") String processDefinitionKey,
                                              @RequestParam("instanceName") String instanceName
                                              //@RequestParam("instanceVariable") String instanceVariable
    ) {

        return service.startProcess(processDefinitionKey, instanceName);

    }


    //启动
    @GetMapping(value = "/startProcessWithVar")
    public ReturnMessage<Object> startProcessWithVar(@RequestParam("processDefinitionKey") String processDefinitionKey,
                                                     @RequestParam("instanceName") String instanceName,
                                                     @RequestParam("instanceVariable") String instanceVariable
    ) {

        return service.startProcessWithVar(processDefinitionKey, instanceName, instanceVariable);

    }


    //删除
    @GetMapping(value = "/deleteInstance")
    public ReturnMessage<Object> deleteInstance(@RequestParam("instanceID") String instanceID) {


        return service.deleteInstance(instanceID);


    }

    //挂起冷冻
    @GetMapping(value = "/suspendInstance")
    public ReturnMessage<Object> suspendInstance(@RequestParam("instanceID") String instanceID) {

        return service.suspendInstance(instanceID);
    }

    //激活
    @GetMapping(value = "/resumeInstance")
    public ReturnMessage<Object> resumeInstance(@RequestParam("instanceID") String instanceID) {

        return service.resumeInstance(instanceID);
    }


    //获取参数
    @GetMapping(value = "/variables")
    public ReturnMessage<Object> variables(@RequestParam("instanceID") String instanceID) {
        return service.variables(instanceID);
    }


}
